<?php

class FastPHP {
	static function getArray($a,$name){
		if( array_key_exists($name,$a) ) return $a[$name];
		return "";      
	}
	static function canRead ( $filename) {
		  if( empty($filename) ) return false;
      if (!(is_readable($filename))) return false;
      if(is_dir($filename)) return false;
      return true;
  }
  static function canWrite($filename) {
  	if( empty($filename) ) return false;
  	if( !is_readable($filename) )return false;
  	if( is_dir($filename) ) return false;
  	if( is_writeable($filename) ) return false;
  	return true;
  }
  static function arrayToString($a) {
      return json_encode($a,true);
  }
  static function convertUrlQuery($query){
    $queryParts = explode('&', $query);
    $params = array();
    foreach ($queryParts as $param){
        $item = explode('=', $param);
        if( is_array($item) )
        $params[$item[0]] = urldecode($item[1]);
    }
     
    return $params;
  }
  static function url_param($url) {
	   $p = parse_url($url);
	   //$tmp = json_encode($p,true);
	   //SemLog::Debug($tmp);
	   return FastPHP::convertUrlQuery( FastPHP::getArray($p,'query') );	     
	}
}